import { message } from 'antd';
import reqwest from 'reqwest';
let data;

export const reqwest_get = (_url, _data, _then, _error, _this) => {
	reqwest({
    url: window.host + _url,
    method: 'get',
    crossOrigin: true,
    type: 'json',
    data: _data,
    headers: {
      authorization: window.localStorage['token'],
      access_token : window.localStorage['token']
    }
  }).then(function(res) {
    _then(res)
  }).fail(function(err,msg) {
    message.error('网络连接失败', 0.6)
  });
}
export const reqwest_post = (_url, _data, _then) => {
	reqwest({
      url: window.host+_url,
      method: 'post',
      crossOrigin: true,
      type: 'json',
      data: _data,
      withCredentials: false,
      headers: {
        authorization: window.localStorage['token'],
        access_token: window.localStorage['token']
      },
      success: function(res) {
        _then(res)
      },
      error: function(err) {
        message.error(err.msg, 1)
      }
    })
}

function getData(data) {
  data = data
  return data
}
export const reqwest_url = (_url, _method, _data, _then, _error, _this) => {
  // let _dataNode = null;
  // let data ;
  return reqwest({
      url: window.host + _url,
      method: _method,
      crossOrigin: true,
      type: 'json',
      withCredentials: true,
      data: _data,
      // async : false,
      // crossOrigin: true,
      contentType: 'application/json',
      headers: {
         Authorization: window.localStorage['token']
      },
      success: function(res) {
        _then(res)
      },
      error: function(err) {
        message.error(err.msg, 1)
      }
    })
}
